jQuery(function($) {

$('input[type=submit]')
  .attr('onclick', 'return false;')
  .click(function(e) {
    // If bio 25, check wich destination was choose
    var dest2 = $('input[name=destination2]');
    if (dest2.val() != null && dest2.val() != '')
      var destination = '#'+ dest2.val() + ' - Fleet';
    else
      var destination = $('#awplus_planet option[value='+$('#awplus_planet').val()+']').text();

    // Build HTML
    var html = '<div id="ap_launch_confirm" align="center">';
    html += '<table cellspacing="1" cellpadding="1" align="center" style="text-align: center;">';
    html += '<tr bgcolor="#202060"><th nowrap="nowrap">'+$('#awplus_content table:eq(0) tr:eq(0) td:eq(0)').text()+'</th><th>Qty</th></tr>';
    html += '<tr bgcolor="#404040"><td width="250">Transport:</td><td>'+$('input[name=inf]').val()+'</td></tr>';
    html += '<tr bgcolor="#404040"><td>Colony Ship:</td><td>'+$('input[name=col]').val()+'</td></tr>';
    html += '<tr bgcolor="#404040"><td>Destroyer:</td><td>'+$('input[name=des]').val()+'</td></tr>';
    html += '<tr bgcolor="#404040"><td>Cruiser:</td><td>'+$('input[name=cru]').val()+'</td></tr>';
    html += '<tr bgcolor="#404040"><td>Battleship:</td><td>'+$('input[name=bat]').val()+'</td></tr>';
    html += '<tr bgcolor="#202060" align="center"><th colspan="2">Destination</th></tr>';
    html += '<tr bgcolor="#404040"><td>System:</td><td nowrap="nowrap">'+destination+'</td></tr>';
    html += '<tr bgcolor="#404040"><td>ID:</td><td>'+$('input[name=planet]').val()+'</td></tr>';
    html += '<tr bgcolor="#404040"><td>Arrival Time Calculator:</td><td>'+$('#awplus_ttc').text()+'</td></tr>';
    var nap = $('input[name=nap]:checked').size() > 0  ? 'Yes' : 'No';
    html += '<tr bgcolor="#404040"><td>Disregard NAP:</td><td>'+nap+'</td></tr>';
    html += '<tr bgcolor="#602020"><td colspan="2">';
    html += '</td></tr>';
    html += '</table>';
    html += '</div>';

    $('#awplus_content table:eq(0)').attr('id', 'ap_launch_settings').before(html);
    
    $('#ap_launch_confirm').dialog({
      modal: true,
      title: 'Check if your chooses are corrects',
      resizable: false,
      width: 500,
      close: function() {
        $(this).dialog('destroy');
        $(this).remove();
      },
      buttons: {
        'Cancel': function() {
          $(this).dialog('destroy');
          $(this).remove();
        },
        'Launch': function() {
          $('form[name=fleet]')[0].submit();
        }
      }
    });

  });

});
